﻿Imports System.IO.IsolatedStorage
Imports Runa.Scripting
Imports Runa.Resources.ResourceManager
Imports Runa.Core.GamePackage
Imports Runa.Foundation.IO
Imports Runa.Common.Helper
Imports System.Collections

Module Helper

    Public g_gameList As New List(Of GamePackageBase)
    Public g_gamePkg As GamePackageBase
    Public g_fileStorage As GameDirectory
    Public g_externalFiles As New List(Of String)

#If WINDOWS Then
    Public Declare Function TerminateProcess Lib "kernel32" Alias "TerminateProcess" (ByVal hProcess As IntPtr, ByVal uExitCode As UInteger) As Boolean
#End If

    Public Function GetGames() As List(Of GamePackageBase)
        Dim lst As New List(Of GamePackageBase)
        Dim games = g_fileStorage.GetDirectories()
        For Each g In games
            Try
                lst.Add(New RunaGamePackage(g, g_fileStorage))
            Catch ex As Exception
                Debuger.TraceListener.WriteLine(String.Format("{0}: {1}" & vbCrLf, Now.ToString(), ex.Message, ex.StackTrace.ToString()))
            End Try
        Next
        games = g_fileStorage.GetFiles()
        For Each g In games
            Try
                If lst.Contains(Function(item) item.Name.ToLower() = g) Then
                    Continue For
                Else
                    lst.Add(New RunaGamePackage(g, g_fileStorage))
                End If
            Catch ex As Exception
                Debuger.TraceListener.WriteLine(String.Format("{0}: {1}" & vbCrLf, Now.ToString(), ex.Message, ex.StackTrace.ToString()))
            End Try
        Next
        Return lst
    End Function

End Module